/*
 * @lc app=leetcode.cn id=1184 lang=typescript
 *
 * [1184] 公交站间的距离
 */

// @lc code=start
function distanceBetweenBusStops(
    distance: number[],
    start: number,
    destination: number
): number {
    let [small, big] = [
        Math.min(start, destination),
        Math.max(start, destination),
    ];
    let mid = distance.slice(small, big).reduce((a, b) => a + b, 0);
    let side = [...distance.slice(0, small), ...distance.slice(big)].reduce(
        (a, b) => a + b,
        0
    );
    return Math.min(side, mid);
}
// @lc code=end
